package tests;

import static org.junit.Assert.assertTrue;

import java.util.ArrayList;

import models.Post;
import models.User;

import org.junit.Before;
import org.junit.Test;

import filter.FilterPostsByTitle;

public class TestFilterPostsByTitle {

	Post testPost1 = null;
	Post testPost2 = null;
	ArrayList<Post> postList = null;
	ArrayList<Post> filterResult = null;
	FilterPostsByTitle filter = null;

	@Before
	public void createTestPostList() {
		testPost1 = new Post(new User("user1"));
		testPost2 = new Post(new User("user2"));
		testPost1.setTitle("title1");
		testPost2.setTitle("title2");
		postList = new ArrayList<Post>();
		postList.add(testPost1);
		postList.add(testPost2);
	}

	@Test
	public void testConstructor() {
		filter = new FilterPostsByTitle("testTitle");
	}

	@Test
	public void testApplyFilter() {
		filter = new FilterPostsByTitle("1");
		filterResult = filter.applyFilter(postList);
		assertTrue(filterResult.contains(testPost1) && filterResult.size() == 1);

	}

	@Test
	public void testApplyFilterReturnNothing() {
		filter = new FilterPostsByTitle("3");
		filterResult = filter.applyFilter(postList);
		assertTrue(filterResult.size() == 0);
	}

	@Test
	public void testApplyFilterNoTitle() {
		filter = new FilterPostsByTitle("");
		filterResult = filter.applyFilter(postList);
		assertTrue(filterResult.size() == postList.size());
	}

	@Test
	public void testApplyFilterNull() {
		filter = new FilterPostsByTitle(null);
		filterResult = filter.applyFilter(postList);
		assertTrue(filterResult.size() == postList.size());
	}

}
